Adds a line to be added right after #version in GLSL backend. This is useful for enabling custom extensions which are outside the scope of SPIRV-Cross. This can be combined with variable remapping. A new-line will be added.
Legacy GLSL compatibility method. Takes a uniform or push constant variable and flattens it into a (i|u)vec4 arrayN; array instead. For this to work, all types in the block must be the same basic type, e.g. mixing vec2 and vec4 is fine, but mixing int and float is not. The name of the uniform array will be the same as the interface block name.
Returns the current string held in the conversion buffer. Useful for capturing what has been converted so far when compile() throws an error.
Adds an extension which is required to run this shader, e.g. require_extension("GL_KHR_my_extension");
Dispose native resources held by the compiler. It is called during GC collection, but can be also called manually.
After parsing, API users can modify the SPIR-V via reflection and call this to disassemble the SPIR-V into the desired langauage. Sub-classes actually implement this.
Gets the identifier (OpName) of an ID. If not defined, an empty string will be returned.
Applies a decoration to an ID. Effectively injects OpDecorate.
Overrides the identifier OpName of an ID. Identifiers beginning with underscores or identifiers which contain double underscores are reserved by the implementation.
Returns whether the decoration has been applied to the ID.
Gets the value for decorations which take arguments. If the decoration is a boolean (i.e. spv.DecorationNonWritable), 1 will be returned. If decoration doesn't exist or decoration is not recognized, 0 will be returned.
Removes the decoration for an ID.
Gets the SPIR-V type associated with ID. Mostly used with Resource::typeId and Resource::baseTypeId to parse the underlying type of a resource.
Gets the SPIR-V type of a variable.
Gets the id of SPIR-V type underlying the given typeId, which might be a pointer.
Gets the SPIR-V type underlying the given typeId, which might be a pointer.
Gets the underlying storage class for an OpVariable.
If get_name() is an empty string, get the fallback name which will be used instead in the disassembled source.
If get_name() of a Block struct is an empty string, get the fallback name. This needs to be per-variable as multiple variables can use the same block type.
Given an OpTypeStruct in ID, obtain the identifier for member number "index". This may be an empty string.
Given an OpTypeStruct in ID, obtain the OpMemberDecoration for member number "index".
Sets the member identifier for OpTypeStruct ID, member number "index".
Returns the qualified member identifier for OpTypeStruct ID, member number "index", or an empty string if no qualified alias exists
Sets the qualified member identifier for OpTypeStruct ID, member number "index".
Returns whether the decoration has been applied to a member of a struct.
Similar to setDecoration, but for struct members.
Unsets a member decoration, similar to unsetDecoration.
Gets the fallback name for a member, similar to getFallbackName.
Returns a vector of which members of a struct are potentially in use by a SPIR-V shader. The granularity of this analysis is per-member of a struct. This can be used for Buffer (UBO), BufferBlock/StorageBuffer (SSBO) and PushConstant blocks. ID is the Resource::id obtained from get_shader_resources().
Returns the effective size of a buffer block.
Returns the effective size of a buffer block, with a given array size for a runtime array. SSBOs are typically declared as runtime arrays. getDeclaredStructSize() will return 0 for the size. This is not very helpful for applications which might need to know the array stride of its last member. This can be done through the API, but it is not very intuitive how to accomplish this, so here we provide a helper function to query the size of the buffer, assuming that the last member has a certain size. If the buffer does not contain a runtime array, arraySize is ignored, and the function will behave as getDeclaredStructSize(). To get the array stride of the last member, something like: getDeclaredStructSizeRuntimeArray(type, 1) - getDeclaredStructSizeRuntimeArray(type, 0) will work.
Returns the effective size of a buffer block struct member.
Returns a set of all global variables which are statically accessed by the control flow graph from the current entry point. Only variables which change the interface for a shader are returned, that is, variables with storage class of Input, Output, Uniform, UniformConstant, PushConstant and AtomicCounter storage classes are returned.
Sets the interface variables which are used during compilation. By default, all variables are used. Once set, compile() will only consider the set in active_variables.
Query shader resources, use ids with reflection interface to modify or query binding points, etc.
Query shader resources, but only return the variables which are part of active_variables. E.g.: get_shader_resources(get_active_variables()) to only return the variables which are statically accessed.
Remapped variables are considered built-in variables and a backend will not emit a declaration for this variable. This is mostly useful for making use of builtins which are dependent on extensions.
For subpassInput variables which are remapped to plain variables, the number of components in the remapped variable must be specified as the backing type of subpass inputs are opaque.
New variants of entry point query and reflection. Names for entry points in the SPIR-V module may alias if they belong to different execution models. To disambiguate, we must pass along with the entry point names the execution model.
Gets argument for an execution mode (LocalSize, Invocations, OutputVertices). For LocalSize, the index argument is used to select the dimension (X = 0, Y = 1, Z = 2). For execution modes which do not have arguments, 0 is returned.
In SPIR-V, the compute work group size can be represented by a constant vector, in which case the LocalSize execution mode is ignored.
Analyzes all OpImageFetch (texelFetch) opcodes and checks if there are instances where said instruction is used without a combined image sampler. GLSL targets do not support the use of texelFetch without a sampler. To workaround this, we must inject a dummy sampler which can be used to form a sampler2D at the call-site of texelFetch as necessary.
Analyzes all separate image and samplers used from the currently selected entry point, and re-routes them all to a combined image sampler instead. This is required to "support" separate image samplers in targets which do not natively support this feature, like GLSL/ESSL.
Gets a remapping for the combined image samplers.
API for querying which specialization constants exist. To modify a specialization constant before compile(), use get_constant(constant.id), then update constants directly in the SPIRConstant data structure. For composite types, the subconstants can be iterated over and modified. constant_type is the SPIRType for the specialization constant, which can be queried to determine which fields in the unions should be poked at.
API for querying buffer objects. The type passed in here should be the base type of a resource, i.e. getType(resource.baseTypeId) as decorations are set in the basic Block type. The type passed in here must have these decorations set, or an exception is raised. Only UBOs and SSBOs or sub-structs which are part of these buffer types will have these decorations set.
Gets the offset in SPIR-V words (uint) for a decoration which was originally declared in the SPIR-V binary. The offset will point to one or more uint literals which can be modified in-place before using the SPIR-V binary. Note that adding or removing decorations using the reflection API will not change the behavior of this function. If the decoration was declared, sets the word_offset to an offset into the provided SPIR-V binary buffer and returns true, otherwise, returns false. If the decoration does not have any value attached to it (e.g. DecorationRelaxedPrecision), this function will also return false.
HLSL counter buffer reflection interface. Append/Consume/Increment/Decrement in HLSL is implemented as two "neighbor" buffer objects where one buffer implements the storage, and a single buffer containing just a lone "int" implements the counter. To SPIR-V these will be exposed as two separate buffers, but glslang HLSL frontend emits a special indentifier which lets us link the two buffers together.
Queries if a buffer object has a neighbor "counter" buffer. If so, the ID of that counter buffer will be returned in counter_id. If SPV_GOOGLE_hlsl_functionality1 is used, this can be used even with a stripped SPIR-V module. Otherwise, this query is purely based on OpName identifiers as found in the SPIR-V module, and will only return true if OpSource was reported HLSL. To rely on this functionality, ensure that the SPIR-V module is not stripped.
Gets the list of all SPIR-V Capabilities which were declared in the SPIR-V module.
Gets the list of all SPIR-V extensions which were declared in the SPIR-V module.
When declaring buffer blocks in GLSL, the name declared in the GLSL source might not be the same as the name declared in the SPIR-V module due to naming conflicts. In this case, SPIRV-Cross needs to find a fallback-name, and it might only be possible to know this name after compiling to GLSL. This is particularly important for HLSL input and UAVs which tends to reuse the same block type for multiple distinct blocks. For these cases it is not possible to modify the name of the type itself because it might be unique. Instead, you can use this interface to check after compilation which name was actually used if your input SPIR-V tends to have this problem. For other names like remapped names for variables, etc, it's generally enough to query the name of the variables after compiling, block names are an exception to this rule. ID is the name of a variable as returned by Resource::id, and must be a variable with a Block-like type.
Compiler that produces Glsl code